package com.easygem.controller.front;

import com.easygem.common.annotation.ControllerEndpoint;
import com.easygem.common.model.front.CallLog;
import com.easygem.common.response.ResponseBean;
import com.easygem.common.vo.front.CallLogVo;
import com.easygem.common.vo.front.SeatTrafficVo;
import com.easygem.common.vo.system.PageVO;
import com.easygem.front.service.CallLogService;
import com.wuwenze.poi.ExcelKit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author luoxi
 * @version 1.0
 * @className CallLogController
 * @Description TODO
 * @date 2025/3/25 9:14
 */
@Api(tags = "话单日志")
@RestController
@RequestMapping("/system/callLog")
public class CallLogController {
    @Autowired
    private CallLogService callLogService;
    @ApiOperation(value = "话单记录列表", notes = "模糊查询话单记录列表")
    @GetMapping("/findList")
    @ResponseBody
    public ResponseBean<PageVO<CallLog>> findList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                  @RequestParam(value = "pageSize", defaultValue = "7") Integer pageSize,
                                                  CallLogVo callLogVo) {
        PageVO<CallLog> callLogPageVO = callLogService.findList(pageNum, pageSize, callLogVo);
        return ResponseBean.success(callLogPageVO);
    }
    /**
     * 批量导出excel
     * @param response
     */
    @ApiOperation(value = "导出excel", notes = "批量导出话单记录的excel表格")
    @PostMapping("/downExcelBatch")
    @RequiresPermissions("callLog:downExcelBotch")
    @ControllerEndpoint(exceptionMessage = "导出Excel失败",operation = "导出话单记录excel")
    public void batchExport(HttpServletResponse response,@RequestBody List<Long> logId) {
        List<CallLog> tPResources = callLogService.downExcelBatch(logId);
        ExcelKit.$Export(CallLog.class, response).downXlsx(tPResources, false);
    }

    /**
     * 按条件全部导出excel
     * @param response
     */
    @ApiOperation(value = "导出excel", notes = "按条件全部导出话单记录的excel表格")
    @PostMapping("/downExcelAll")
    @RequiresPermissions("callLog:DownExcelAll")
    @ControllerEndpoint(exceptionMessage = "导出Excel失败",operation = "导出话单记录excel")
    @ResponseBody
    public void export(HttpServletResponse response,@RequestBody CallLogVo callLogVo){
            List<CallLog> callLogList = this.callLogService.downExcelAll(callLogVo);
            ExcelKit.$Export(CallLog.class, response).downXlsx(callLogList, false);

    }


    @ApiOperation(value = "坐席话务统计列表", notes = "模糊查询坐席话务统计列表")
    @GetMapping("/findListSeatTraffic")
    @ResponseBody
    public ResponseBean<PageVO<SeatTrafficVo>> getCallLogListByCallLog(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", defaultValue = "7")  Integer pageSize, CallLogVo callLogVo) {
        PageVO<SeatTrafficVo> callLogPageVO = callLogService.getCallLogListByCallLog(pageNum, pageSize, callLogVo);
        return ResponseBean.success(callLogPageVO);
    }

    /**
     * 批量导出excel
     * @param response
     */
    @ApiOperation(value = "导出excel", notes = "批量导出坐席话务记录的excel表格")
    @PostMapping("/seatTrafficDownExcelBatch")
    @RequiresPermissions("seatTraffic:downExcelBotch")
    @ControllerEndpoint(exceptionMessage = "导出Excel失败",operation = "导出话单记录excel")
    @ResponseBody
    public void seatTrafficDownExcelBatch(HttpServletResponse response,@RequestBody CallLogVo callLogVo) {
        System.out.println("@@@@@@@@@@@@###############$$$$$$$$$$$$$$$$$$$$$$:"+callLogVo.toString());
        List<SeatTrafficVo> tPResources = callLogService.seatTrafficDownExcelBatch(callLogVo);
        ExcelKit.$Export(SeatTrafficVo.class, response).downXlsx(tPResources, false);
    }

    /**
     * 按条件全部导出excel
     * @param response
     */
    @ApiOperation(value = "导出excel", notes = "按条件全部导出坐席话务记录的excel表格")
    @PostMapping("/seatTrafficDownExcelAll")
    @RequiresPermissions("seatTraffic:DownExcelAll")
    @ControllerEndpoint(exceptionMessage = "导出Excel失败",operation = "导出话单记录excel")
    @ResponseBody
    public void seatTrafficDownExcelAll(HttpServletResponse response,@RequestBody CallLogVo callLogVo){
        List<SeatTrafficVo> seatTrafficVos = this.callLogService.seatTrafficDownExcelAll(callLogVo);
        ExcelKit.$Export(SeatTrafficVo.class, response).downXlsx(seatTrafficVos, false);

    }
}
